import router from '@/router'
import {setStore,removeStore} from '@/lib/store'

export default {
	//用户信息
	USER_INFO(state,user){
		//保存token信息
		setStore({name:'token',content:user.token});
		//保存用户信息
		setStore({name:'userInfo',content:user});
		//保存用户信息
		setStore({name:'rules',content:user.rules});
		state.userInfo = user;
		state.rules = user.rules;
		state.token = user.token;
	},
	//权限过滤
	AUTH(){
		
	},
	//选中当前菜单
	MENU_SELECT(state,data){
		router.push(data) // 路由跳转
		state.menuActive = data // 选择菜单
		state.menuOpened = `/${data.split('/')[1]}` // 展开菜单
		setStore({name:'menuActive',content:data});
		setStore({name:'menuOpened',content:state.menuOpened});
	},
	//退出清除数据
	LOGOUT(state){
		let remove = ['token','userInfo'];
		state.userInfo = {};
		remove.forEach(item=>{
			removeStore({name:item})
		})
	}

}
